#include <head.h>

int main(int argc, char const *argv[])
{
	if (argc != 2)
	{
		printf("格式错误: %s [port]\n", argv[0]);
		exit(1);
	}

	// 创建用户数据报 套接字
	int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (-1 == sock_fd)
	{
		ERRLOG("套接字创建错误");
		return 0;
	}

	struct sockaddr_in server_addr;

	memset(&server_addr, 0, sizeof(server_addr));

	server_addr.sin_family = AF_INET;

	server_addr.sin_port = htons(atoi(argv[1]));

	server_addr.sin_addr.s_addr = inet_addr("192.168.20.236");

	socklen_t server_addr_len = sizeof(server_addr);

	char buf[1024];
	memset(buf, 0, sizeof(buf));

	while (1)
	{
		printf("输入:");
		scanf("%s", buf);

		sendto(sock_fd, buf, strlen(buf), 0, (struct sockaddr *)&server_addr, server_addr_len);

		memset(buf, 0, sizeof(buf));

		recvfrom(sock_fd, buf, sizeof(buf), 0, (struct sockaddr *)&server_addr, &server_addr_len);

		printf("接收:%s\n", buf);

		memset(buf, 0, sizeof(buf));
	}

	close(sock_fd);
	return 0;
}